﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;

using System.Windows;
using Styx;
using Styx.Helpers;
using Styx.Plugins;
using Styx.Common;
using Styx.CommonBot;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.Pathing;

namespace EggCollector
{
    public class EggCollector : HBPlugin
    {
        public override string Name
        {
            get { return "Egg Collector"; }
        }

        public override string Author
        {
            get { return "Silent"; }
        }

        public override Version Version
        {
            get { return new Version(1, 0); }
        }

        public override bool WantButton
        {
            get { return false; }
        }

        public override void Initialize()
        {
        }


        public override void Pulse()
        {
            var me = StyxWoW.Me;
            if (!StyxWoW.IsInWorld || !me.IsValid && me.IsDead)
            {
                return;
            }

            var chest = ObjectManager.GetObjectsOfType<WoWGameObject>().FirstOrDefault(obj => obj.Entry == 113768);
            if (chest != null && chest.IsValid)
            {
                while (chest.IsValid)
                {
                    if (chest.WithinInteractRange)
                    {
                        if (me.IsMoving)
                        {
                            WoWMovement.MoveStop();
                        }
                        if (!me.IsCasting)
                        {
                            chest.Interact();
                        }
                    }
                    else
                    {
                        Navigator.MoveTo(chest.Location);
                    }
                    ObjectManager.Update();
                }
            }
        }

    }
}
